package com.ruoyi.basebill.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basebill.domain.OmsReceiptbill;
import com.ruoyi.basebill.service.IOmsReceiptbillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * OMS收货确认Controller
 * 
 * @author ptt
 * @date 2023-02-10
 */
@RestController
@RequestMapping("/settlementCenter/basebill/receiptbill")
public class OmsReceiptbillController extends BaseController
{
    @Autowired
    private IOmsReceiptbillService omsReceiptbillService;

    /**
     * 查询OMS收货确认列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsReceiptbill omsReceiptbill)
    {
        startPage();
        List<OmsReceiptbill> list;
        String sumbillNumber = omsReceiptbill.getSumbillNumber();
        if (StringUtils.isEmpty(sumbillNumber)){
            list = omsReceiptbillService.selectOmsReceiptbillList(omsReceiptbill);
        }else {
            list = omsReceiptbillService.selectOmsReceiptbillBySumbill(omsReceiptbill);
        }
        return getDataTable(list);
    }

    /**
     * 导出OMS收货确认列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:export')")
    @Log(title = "OMS收货确认", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsReceiptbill omsReceiptbill)
    {
        List<OmsReceiptbill> list = omsReceiptbillService.selectOmsReceiptbillDetailList(omsReceiptbill);
        ExcelUtil<OmsReceiptbill> util = new ExcelUtil<OmsReceiptbill>(OmsReceiptbill.class);
        util.exportExcel(response, list, "OMS收货确认数据");
    }

    /**
     * 获取OMS收货确认详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(omsReceiptbillService.selectOmsReceiptbillById(id));
    }

    /**
     * 新增OMS收货确认
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:add')")
    @Log(title = "OMS收货确认", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsReceiptbill omsReceiptbill)
    {
        return toAjax(omsReceiptbillService.insertOmsReceiptbill(omsReceiptbill));
    }

    /**
     * 修改OMS收货确认
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:edit')")
    @Log(title = "OMS收货确认", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsReceiptbill omsReceiptbill)
    {
        return toAjax(omsReceiptbillService.updateOmsReceiptbill(omsReceiptbill));
    }

    /**
     * 删除OMS收货确认
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basebill:receiptbill:remove')")
    @Log(title = "OMS收货确认", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsReceiptbillService.deleteOmsReceiptbillByIds(ids));
    }
}
